package com.dog.modules.websocket.domain.enums;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

public enum ClientTypeEnum {

    OP("1", "OP"),
    BIZ("2", "BIZ"),
    APP("3", "APP");

    private static final Map<String, String> VALUES_MAP;

    static {
        Map<String, String> map = new LinkedHashMap<>();
        for (ClientTypeEnum each : values()) {
            map.put(each.getCode(), each.getName());
        }
        VALUES_MAP = Collections.unmodifiableMap(map);
    }

    private final String code;
    private final String name;

    ClientTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static Map<String, String> toMap() {
        return VALUES_MAP;
    }

    public static ClientTypeEnum getEnumByCode(String code) {
        for (ClientTypeEnum each : values()) {
            if (each.getCode().equals(code)) {
                return each;
            }
        }
        return null;
    }

    public static String getNameByCode(String code) {
        ClientTypeEnum en = getEnumByCode(code);
        if (null != en) {
            return en.getName();
        }
        return null;
    }
}
